package com.wzx.user.utils;

import org.springframework.util.StringUtils;

/**
 * @author wzx
 * @version 1.0
 * @date 2023/5/6 - 18:46
 * @description 标题
 */
public class AmountUtils {

    /**
     * 1，int以分为单位金额，转为 double小数点后两位
     *
     * @param amount
     * @return
     */
    public static double handlerAmountByDouble(Integer amount) {
        if (StringUtils.isEmpty(amount)) {
            return 0;
        }
        return Double.parseDouble(amount + "") / Double.parseDouble("100");
    }

    /**
     * 2，double小数点后两位金额，转为以分为单位
     *
     * @param amount
     * @return
     */
    public static Integer handlerAmountByInteger(double amount) {
        if (StringUtils.isEmpty(amount)) {
            return 0;
        }
        return (int) (amount * 100);
    }

    /**
     * 3，手续费计算
     *  (元数据 * 0.01 + 1)
     * @param price
     * @return
     */
    public static double countCommission(double price) {
        double comPrice = price * 0.01;
        //保留两位小数
        String str = String.format("%.2f", comPrice);
        double four = Double.parseDouble(str);
        return four + 1.00;
    }


}
